package com.sctvcloud.dongqu.ui.adapter.holder;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.ruihang.generalibrary.ui.adapter.holder.BaseRecylerHolder;
import com.ruihang.generalibrary.ui.widget.CustomEXImageView;
import com.ruihang.generalibrary.ui.widget.CustomFontTextView;
import com.ruihang.generalibrary.utils.DateUtils;
import com.sctvcloud.dongqu.R;
import com.sctvcloud.dongqu.beans.FCollect;
import com.sctvcloud.dongqu.ui.utils.GlideUtil;
import com.sctvcloud.dongqu.ui.utils.UIUtils;
import com.sctvcloud.dongqu.utils.TimeUtils;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/6/22 0022.
 */

public class MyCollectionHolder extends BaseRecylerHolder<FCollect> implements View.OnClickListener {
    @BindView(R.id.item_tv_title)
    protected CustomFontTextView tvTitle;
    @BindView(R.id.item_tv_time)
    protected CustomFontTextView tvTime;
    @BindView(R.id.item_tv_type)
    protected CustomFontTextView tvType;
    @BindView(R.id.item_iv_img)
    protected CustomEXImageView ivImg;
    @BindView(R.id.item_news_type)
    protected ImageView news_type;
    @BindView(R.id.item_video_play_length)
    protected CustomFontTextView play_length;
    @BindView(R.id.item_iv_img_layout)
    protected RelativeLayout item_iv_img_layout;
    @BindView(R.id.newes_detail_click_count)
    protected CustomFontTextView clickcount;

    private FCollect mFCollect;

    public MyCollectionHolder(Context context, View itemView) {
        super(context, itemView);
        itemView.setOnClickListener(this);
    }

    @Override
    protected void initInject() {
        ButterKnife.bind(this, itemView);
    }

    @Override
    public void setData(FCollect fCollect) {
        mFCollect = fCollect;
        clickcount.setText(UIUtils.getReadingNumber(fCollect.getViews()));
        tvTitle.setText(TextUtils.isEmpty(fCollect.getTitle()) ? "" : fCollect.getTitle());
        tvTime.setText(TextUtils.isEmpty(fCollect.getTime()) ? "" : DateUtils.formatDate(DateUtils
                .getDataDate(fCollect),""));
        tvType.setText(TextUtils.isEmpty(fCollect.getLable()) ? "" : fCollect.getLable());
        tvType.setVisibility(View.GONE);
        if (!TextUtils.isEmpty(fCollect.getImg())) {
            GlideUtil.loadImgSmall169Def(context, fCollect.getImg(), ivImg);
            item_iv_img_layout.setVisibility(View.VISIBLE);
            tvTitle.setLines(3);
        } else {
            ivImg.setImageResource(R.mipmap.icon_def_16_9_s);
            item_iv_img_layout.setVisibility(View.GONE);
            tvTitle.setMaxLines(2);
        }
//        if (!TextUtils.isEmpty(fCollect.getNewsMediaLength())) {
//            play_length.setVisibility(View.VISIBLE);
//            play_length.setText(TimeUtils.formatTimeToHM(fCollect.getNewsMediaLength()));
//        } else {
//            play_length.setVisibility(View.GONE);
//        }
        if (fCollect.getDataType() == 2) { //音频
            news_type.setImageResource(R.mipmap.icon_home_voice);
            news_type.setVisibility(View.VISIBLE);
        } else if (fCollect.getDataType() == 3) {   //视频
            news_type.setImageResource(R.mipmap.icon_home_play);
            news_type.setVisibility(View.VISIBLE);
        } else {
            news_type.setVisibility(View.GONE);
        }
    }

    @Override
    public void onClick(View v) {
        if (internalClick != null) {
            itemView.setTag(R.id.adapter_item_data_key, mFCollect);
            internalClick.onItemInternalClick(itemView, v, getAdapterPosition());
        }
    }
}
